package net.sf.flock.webapp.tree;
import java.util.Collection;
import java.util.Iterator;
import net.sf.tapestry.AbstractComponent;
import net.sf.tapestry.IBinding;
import net.sf.tapestry.IMarkupWriter;
import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.RequestCycleException;
import net.sf.flock.tree.ITreeNode;
public class Tree extends AbstractComponent {
private ITreeNode rootNode;
private int depth = 0;
private ITreeNode value;
private IBinding valueBinding;
public ITreeNode getRootNode() {
return rootNode;
}
public void setRootNode(ITreeNode rootNode) {
this.rootNode = rootNode;
public int getDepth() {
return depth;
public ITreeNode getValue() {
return this.value;
public IBinding getValueBinding() {
return valueBinding;
public void setValueBinding(IBinding valueBinding) {
this.valueBinding = valueBinding;
/**
* @see net.sf.tapestry.AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle)
*/
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
this.enterChildren(writer, cycle);
this.renderNodes(writer, cycle, this.rootNode);
this.leaveChildren(writer, cycle);
protected void renderNodes(IMarkupWriter writer, IRequestCycle cycle, ITreeNode node) throws RequestCycleException {
this.depth++;
this.value = node;
if (this.valueBinding!=null) {
this.valueBinding.setObject(value);
this.enterNode(writer, cycle);
this.renderCurrentNode(writer, cycle);
Collection children = node.getChildren();
if (children!=null) {
for (Iterator i=children.iterator(); i.hasNext(); ) {
this.renderNodes( writer, cycle, (ITreeNode)i.next() );
this.leaveNode(writer, cycle);
this.depth--;
protected void enterNode(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
protected void leaveNode(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
protected void enterChildren(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
protected void leaveChildren(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
protected void renderCurrentNode(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException {
this.renderBody(writer, cycle);